Skip to main content

Example: Using Markers with Barikoi React GL

The Marker component in the react-bkoi-gl package allows developers to place customizable markers at specific geographic coordinates on the map. These markers can represent points of interest, locations, or other notable spots, offering a clear visual indicator for users. With the ability to style and position markers flexibly, the Marker component enhances the map’s interactivity by making it easier for users to identify important locations. This feature is essential for applications that require pinpointing places, such as navigation, event tracking, or location-based services.

Example

"use client";
import { useRef } from 'react';
import { Map, Marker } from 'react-bkoi-gl'; // Import the Barikoi React GL package
import "react-bkoi-gl/styles" // Import CSS for proper map styling

const App = () => {
const BARIKOI_API_KEY = 'YOUR_BARIKOI_API_KEY_HERE'
const mapStyle = `https://map.barikoi.com/styles/osm-liberty/style.json?key=${BARIKOI_API_KEY}`
const mapContainer = useRef(null);
const mapRef = useRef(null);
const initialViewState = {
longitude: 90.36402,
latitude: 23.823731,
minZoom: 4,
maxZoom: 30,
zoom: 13,
bearing: 0,
pitch: 0,
antialias: true
}

return (
<div
ref={mapContainer} style={containerStyles}
>
<Map
ref={mapRef}
mapStyle={mapStyle}
style={{ width: "100%", height: "100%" }}
initialViewState={initialViewState}
doubleClickZoom={false}
dragRotate={false}
attributionControl={false}
>
<Marker
longitude={90.36402}
latitude={23.823731}
anchor="bottom"
>
<img src="./pin.png" />
</Marker>
</Map>
</div>
)
}

// JSX Styles
const containerStyles = {
width: "100%",
height: "100vh",
minHeight: "400px",
overflow: "hidden",
}

export default App